import { useAppDispatch, useAppSelector } from "@/store";
import { decrement, increment, incrementAsync } from "@/store/counter/counterSlice";
import { Button } from "antd";

function Counter() {
  const count = useAppSelector(state => state.counter);
  const dispatch = useAppDispatch();

  function add() {
    dispatch(increment());
  }

  function minus() {
    dispatch(decrement());
  }

  function addSync() {
    dispatch(incrementAsync());
  }

  return (
    <>
      <h4>Count:{count}</h4>
      <Button onClick={add}>+1</Button>
      <Button onClick={minus}>-1</Button>
      <Button onClick={addSync}>异步+3</Button>
    </>
  );
}

export default Counter;
